package com.android.pagemarket.business.model;

import java.io.Serializable;

import org.json.JSONObject;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName="messages")
public class Message implements Serializable
{
    private static final long serialVersionUID = 7406396885411520750L;
    
    /** 快讯类型*/
    public static final int TYPE_ALERTS = 0;
    /** 促销类型*/
    public static final int TYPE_PROMOT = 1;
    /////////////////////////////////////////////////////
    // 数据库参数
    // 类型
    @DatabaseField(uniqueCombo=true)
    public int type = TYPE_ALERTS;
    // 是否已读
    @DatabaseField
    public boolean isRead = false;
    /////////////////////////////////////////////////////
    // 协议参数
    @DatabaseField(id=true,uniqueCombo=true)
    public int no;

    public String imageURL;// 否 C 快讯图片

    public String title;// 是 C 标题

    public String content;// 是 C 内容

    public boolean header;// 是 B 是否是头条

    public String quotCall;// 是 C 报价电话号码
    /////////////////////////////////////////////////////
    public static Message parse(JSONObject data, int type) throws Exception
    {
        Message one = new Message();

        one.type = type;
        one.no = data.getInt("no");
        one.title = data.getString("title");
        one.content = data.getString("content");
        if(type == TYPE_ALERTS)
        {
            if (!data.isNull("header")) one.header = data.getBoolean("header");
        }else
        {
            if (!data.isNull("quotCall")) one.quotCall = data.getString("quotCall");
        }
        if (!data.isNull("imageURL"))
        {
            one.imageURL = data.getString("imageURL");
        }
        return one;
    }
}